package top.bigdata.controller;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import top.bigdata.model.dto.MonthlyData;
import top.bigdata.model.dto.Response;
import top.bigdata.model.dto.TagData;
import top.bigdata.service.api.TagIService;

import java.util.List;

@RestController
@RequiredArgsConstructor
@RequestMapping("/tag")
@Tag(name = "标签接口")
public class TagController {
    private final TagIService tagService;

    @GetMapping("/hotTag")
    @Operation(
            summary = "获取最热标签",
            parameters = {@Parameter(name = "tid", description = "分区id，为0时获取全站标签")},
            description = "最热门标签前100个",
            responses = {
                    @ApiResponse(description = "成功", responseCode = "200"),
                    @ApiResponse(description = "失败", responseCode = "500")
            }
    )
    public Response<List<TagData>> getHotTag(
            @RequestParam(name = "tid", defaultValue = "0", required = false) int tid
    ) {
        return Response.success(tagService.getHotTags(tid));
    }

    @GetMapping("/getDataMonthly")
    @Operation(summary = "获取标签各指标平均数的月度数据",
            parameters = {@Parameter(name = "tag", description = "标签名")})
    public Response<List<MonthlyData>> getDataMonthly(@RequestParam(name = "tag") String tag) {
        return Response.success(tagService.getDataMonthly(tag));
    }
}
